package at.fhooe.mc.msports;

import java.util.Vector;

import net.rim.device.api.util.MathUtilities;

public class Session {

	private int steps = 0; // steps
	private float distance = 0.0f; // km
	private float avgSpeed = 0.0f; // kph
	private int heartRate = 0; // bpm
	private float stepFrequency =0.0f; // steps per minute
	private long duration = 0; // time seconds
	private float kCalories= 0; // kilo calories
	private long timeStamp = 0;
	private int avgHeartrate =0;
	private int minHeartrate = Integer.MAX_VALUE;
	private int maxHeartrate = Integer.MIN_VALUE;
	private int percentageOfHRmax = 0;
	private float trimp = 0.0f;
	private long sumHeartRate=0;
	private int countHeartRate=0;
	private static int STEP_SIZE=75;
	
	private Vector heartRateTrace;
	private Vector caloriesTrace;
	private Vector timeStamps;
	private Vector stepCount;
	private Vector speedTrace;
	
	public Session(int steps) {
		this.steps = steps;
		heartRateTrace = new Vector();
		caloriesTrace = new Vector();
		timeStamps = new Vector();
		stepCount = new Vector();
		speedTrace = new Vector();
	}

	public Session(int steps, float distance, float avgSpeed, int heartRate,
			float stepFrequency, long duration, float kCalories,long timeStamp,
			int avgHeartrate, int minHeartrate, int maxHeartrate, int percenatageofHRmax,
			float trimp) {
		this.steps = steps;
		this.distance = distance;
		this.avgSpeed = avgSpeed;
		this.heartRate = heartRate;
		this.stepFrequency = stepFrequency;
		this.duration = duration;
		this.kCalories = kCalories;
		this.timeStamp=timeStamp;
		this.avgHeartrate = avgHeartrate;
		this.minHeartrate = minHeartrate;
		this.maxHeartrate = maxHeartrate;
		this.percentageOfHRmax = percenatageofHRmax;
		this.trimp = trimp;
	}

	public int getSteps() {
		return steps;
	}

	public void setSteps(int steps) {
		this.steps = steps;
	}

	public float getDistance() {
		return steps*STEP_SIZE/100000f;
	}

	public void setDistance(float distance) {
		this.distance = distance;
	}

	public float getAvgSpeed() {
		return getDistance()/(duration/3600.0f);
	}

	public void setAvgSpeed(float avgSpeed) {
		this.avgSpeed = avgSpeed;
	}

	public int getHeartRate() {
		return heartRate;
	}

	public void setHeartRate(int heartrate) {
		sumHeartRate+=heartrate;
		countHeartRate++;
		if(heartrate>maxHeartrate)
			maxHeartrate=heartrate;
		if(heartrate<minHeartrate)
			minHeartrate=heartrate;
		this.heartRate = heartrate;
		heartRateTrace.addElement(String.valueOf(heartrate));
		timeStamps.addElement(String.valueOf(System.currentTimeMillis()));
		stepCount.addElement(String.valueOf(SessionScreen.DEFAULT_STEPS - getSteps()));
		speedTrace.addElement(String.valueOf(getAvgSpeed()));
	}

	public float getStepFrequency() {
		return (float) (steps * (60.0/duration));
	}

	public void setStepFrequency(float stepFrequency) {
		this.stepFrequency = stepFrequency;
	}

	public long getDuration() {
		return duration;
	}

	public void setDuration(long duration) {
		this.duration = duration;	
	}

	public float getKcalories() {
		return  kCalories;
	}
	
	public void setKCalories(float kCal){
		kCalories = kCal;
		caloriesTrace.addElement(String.valueOf(kCalories));
	}
	
	public long getTimeStamp() {
		return timeStamp;
	}

	public void setTimeStamp(long timeStamp) {
		this.timeStamp = timeStamp;
	}
	
	public int getAvgHeartRate() {
		return (int)sumHeartRate/countHeartRate;
	}

	public void setAvgHeartRate(int hearrate) {
		this.avgHeartrate = hearrate;
	}
	
	public int getMinHeartRate() {
		
		return minHeartrate==Integer.MAX_VALUE?0:minHeartrate;
	}

	public void setMinHeartRate(int hearrate) {
		this.minHeartrate = hearrate;
	}
	
	public int getMaxHeartRate() {
		return maxHeartrate==Integer.MIN_VALUE?0:maxHeartrate;
	}

	public void setMaxHeartRate(int hearrate) {
		this.maxHeartrate = hearrate;
	}
	
	public int getPercentageOfHRMax() {
		return (int)(getHeartRate()/PersonalData.getHRMax()*100);
	}

	public void setPercentageOfHRMax(int percent) {
		this.percentageOfHRmax = percent;
	}
	
	public float getTrimp() {
		return trimp;
	}

	public void setTrimp(float trimp) {
		this.trimp = trimp;
	}
	
	public Vector getHeartRateTrace(){
		return heartRateTrace;
	}
	
	public Vector getCalorieTrace(){
		return caloriesTrace;
	}
	
	public Vector getTimeStamps(){
		return timeStamps;
	}
	
	public Vector getStepTrace(){
		return stepCount;
	}
	
	public Vector getSpeedTrace(){
		return speedTrace;
	}
}
